﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Ex4.Company
{
    class Person
    {
        public string firstName;
        public string lastName;
        public Person(string fName, string lName)
        {
            string expression = "^[A-Z][a-z]*$";
            if (Regex.IsMatch(fName,expression))
            {
                this.firstName = fName;
            }
            else
            {
                throw new ArgumentException("Firstname must contain only letters!");
            }
            if (Regex.IsMatch(lName, expression))
            {
                this.lastName = lName;
            }
            else
            {
                throw new ArgumentException("Lastname must contain only letters!");
            }
        }
    }
    class Company
    {
        private string name;
        private string address;
        private string phone;
        private string taxNumber;
        private Person managingDirector;

        public string Name
        {
            get
            {
                return this.name;
            }
            set
            {
                string expression = "^[a-zA-Z][a-zA-Z ]*[a-zA-Z]?$";
                if (Regex.IsMatch(value, expression))
                {
                    this.name = value;
                }
                else
                {
                    throw new ArgumentException("Name must contain only letters!");
                }
            }
        }
        public string Address
        {
            get
            {
                return this.address;
            }
            set
            {
                if (value != null)
                    this.address = value;
                else
                    throw new ArgumentNullException("Adress cannot be null!");
            }
        }
        public string Phone
        {
            get
            {
                return this.phone;
            }
            set
            {
                string expression = @"((\(\d{3}\) ?)|(\d{3}-))?\d{3}-\d{4}";
                if (Regex.IsMatch(value, expression))
                {
                    this.phone = value;
                }
                else
                {
                    throw new ArgumentException("Phone number must be in (123) 456-7890 or 123-456-7890 format !");
                }
            }
        }
        public string TaxNumber
        {
            get
            {
                return this.taxNumber;
            }
            set
            {
                if (value != null)
                    this.taxNumber = value;
                else
                    throw new ArgumentNullException("TaxNumber cannot be null!");
            }
        }
        public Person ManagingDirector
        {
            get
            {
                return this.managingDirector;
            }
            set
            {
                if (value != null)
                    this.managingDirector = value;
                else
                    throw new ArgumentNullException("Managing director cannot be null!");
            }
        }

        public Company(string name, string address, string phone, string taxNumber, Person director)
        {
            this.Name = name;
            this.Address = address;
            this.Phone = phone;
            this.TaxNumber = taxNumber;
            this.managingDirector = director;
        }
    }
    class CompanyTest
    {
        static void Main(string[] args)
        {
            Company myCompany = new Company("Kiwi", "Sofia St. John's Boulevard", "(02) 123-1233", "S0ETax",
                new Person("John", "Smith"));
        }
    }
}
